home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ArrayOb.h < prev    next >
C/C++ Source or Header  |  1990-05-15  |  3KB  |  60 lines

  1. #ifndef ARRAYOB_H
  2. #define ARRAYOB_H
  3.  
  4. // ArrayOb.h -- Basic polymorphic array of objects
  5.  
  6. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ArrayOb.h,v 3.0 90/05/15 22:43:21 kgorlen Rel $
  7.  
  8. #include "Collection.h"
  9.  
  10. class Iterator;                                               // +
  11.  
  12. class ArrayOb: public Collection {
  13.     DECLARE_MEMBERS(ArrayOb);
  14.     Object** v;                                               // +
  15.     unsigned sz;                                              // +
  16.     void allocSizeErr() const;                                // +
  17.     void indexRangeErr() const;                               // +
  18. protected:              // storer() functions for object I/O
  19.     virtual void storer(OIOofd&) const;
  20.     virtual void storer(OIOout&) const;
  21. public:
  22.     ArrayOb(unsigned size =DEFAULT_CAPACITY);                 // +
  23.     ArrayOb(const ArrayOb&);                                  // +
  24.     ~ArrayOb()  { delete v; }                                 // +
  25.     void operator=(const ArrayOb&);                           // +
  26.     bool operator==(const ArrayOb&) const;
  27.     bool operator!=(const ArrayOb& a) const { return !(*this==a); }
  28.     Object*& operator[](int i) {                              // +
  29.         if ((unsigned)i >= sz) indexRangeErr();               // +
  30.         return v[i];                                          // +
  31.     }                                                         // +
  32.     const Object *const& operator[](int i) const {            // +
  33.         if ((unsigned)i >= sz) indexRangeErr();               // +
  34.         return v[i];                                          // +
  35.     }                                                         // +
  36.     virtual Collection& addContentsTo(Collection&) const;     // +
  37.     virtual Object*& at(int i);                               // +
  38.     virtual const Object *const& at(int i) const;             // +
  39.     virtual unsigned capacity() const;                        // +
  40.     virtual int compare(const Object&) const;
  41.     virtual void deepenShallowCopy();
  42.     virtual Object* doNext(Iterator&) const;                  // +
  43.     virtual unsigned hash() const;
  44.     virtual bool isEqual(const Object&) const;
  45.     virtual void reSize(unsigned);                            // +
  46.     virtual void removeAll();                                 // +
  47.     virtual unsigned size() const;                            // +
  48.     virtual const Class* species() const;
  49. private:                // shouldNotImplement();
  50.     virtual Object* add(Object&);                             // +
  51.     virtual unsigned occurrencesOf(const Object&) const;      // +
  52.     virtual Object* remove(const Object&);                    // +
  53. private:                // Not described in book              // +
  54.     Object*& elem(int i)                    { return v[i]; }  // +
  55.     const Object *const& elem(int i) const  { return v[i]; }  // +
  56.     virtual void sort();                                      // +
  57. };
  58.  
  59. #endif
  60.